package cn.isjinhao.se.sql.grammar.statement.retrieve.represention;

import cn.isjinhao.se.sql.grammar.CurdStatementVisitor;
import cn.isjinhao.se.sql.grammar.statement.retrieve.SingleSelectMetaInfo;
import cn.isjinhao.se.sql.grammar.CurdStatement;
import cn.isjinhao.se.sql.grammar.statement.retrieve.SingleSelectType;

/**
 * @author 01395265
 * @date 2021/3/3
 */
public class SingleSelect extends CurdStatement {

    private SingleSelectMetaInfo singleSelectMetaInfo;

    private SingleSelectType singleSelectType = SingleSelectType.UNDETERMINED;

    /**
     * 表示此表是什么类型的表：顶层的select、inCondition、existsCondition或真实表
     */
    private CurdStatement parentCurdStatement;

    private CurdStatement columnSeg;

    private CurdStatement tableSeg;

    private CurdStatement whereSeg;

    private CurdStatement groupBySeg;

    private CurdStatement orderBySeg;

    private CurdStatement limitSeg;

    public SingleSelect(CurdStatement columnSeg, CurdStatement tableSeg, CurdStatement whereSeg,
                        CurdStatement groupBySeg, CurdStatement orderBySeg, CurdStatement limitSeg) {
        this.columnSeg = columnSeg;
        this.tableSeg = tableSeg;
        this.whereSeg = whereSeg;
        this.groupBySeg = groupBySeg;
        this.orderBySeg = orderBySeg;
        this.limitSeg = limitSeg;
    }

    public Object getParentSelectStatement() {
        return parentCurdStatement;
    }

    public void setParentSelectStatement(CurdStatement parentCurdStatement) {
        this.parentCurdStatement = parentCurdStatement;
    }

    public SingleSelectType getSingleSelectType() {
        return singleSelectType;
    }

    public void setSingleSelectType(SingleSelectType singleSelectType) {
        this.singleSelectType = singleSelectType;
    }

    @Override
    public <R> R accept(CurdStatementVisitor<R> curdStatementVisitor) {
        return curdStatementVisitor.visitSingleSelect(this);
    }

    public CurdStatement getColumnSeg() {
        return columnSeg;
    }

    public CurdStatement getTableSeg() {
        return tableSeg;
    }

    public CurdStatement getWhereSeg() {
        return whereSeg;
    }

    public CurdStatement getGroupBySeg() {
        return groupBySeg;
    }

    public CurdStatement getOrderBySeg() {
        return orderBySeg;
    }

    public CurdStatement getLimitSeg() {
        return limitSeg;
    }

    public void setAstMetaInfo(SingleSelectMetaInfo singleSelectMetaInfo) {
        this.singleSelectMetaInfo = singleSelectMetaInfo;
    }
    public SingleSelectMetaInfo getSingleSelectAstMetaInfo() {
        return singleSelectMetaInfo;
    }
}
